package javax.realtime;

import esrc.c9cf.SizeOf;

public final class SizeEstimator {

	private long estimate = 0;
	
	public SizeEstimator(){}
	public long getEstimate()
	{
		return estimate;
	}
	public void reserve(Class c, int number)
	{
		if(c == null) throw new IllegalArgumentException();
		if(c.isPrimitive() || c.isArray() || c.isInterface()) throw new IllegalArgumentException();
		estimate += number * SizeOf.sizeof(c);		
	}
	public void reserve(SizeEstimator size)
	{
		reserve(size, 1);
	}
	public void reserve(SizeEstimator estimator, int number)
	{
		if(estimator == null) throw new IllegalArgumentException();
		this.estimate += estimator.getEstimate() * number;
	}
	public void reserveArray(int length)
	{
		reserveArray(length, getClass());
	}
	public void reserveArray(int length, Class type)
	{
		if(length < 0 || !type.isPrimitive()) throw new IllegalArgumentException();
		estimate += length * SizeOf.sizeof(type); 
	}
}
